use std::fmt::{Display, Formatter};

fn reverse(pair: (i32, bool)) -> (bool, i32) {
    // 用let把一个元组的成员绑定到一些变量
    let (iii, bbb) = pair;
    (bbb, iii)
}

#[derive(Debug)]
struct Matrix(f32, f32, f32, f32);

impl Display for Matrix {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        write!(f, "({} {}) \n({} {})", self.0, self.1, self.2, self.3)
    }
}

fn main() {
    let long_tuple = (1u32, 2i32, 3u16, 4u64
                      , -1i8, -2i16, -3i32, -4i64,
                      0.1f32, 0.2f64,
                      'a', true);
    println!("第4个值={}", long_tuple.3);

    let tuple_of_tuple = (long_tuple, 1i32, (1i32, 3u32));
    println!("{:?},{:?}", tuple_of_tuple.0, tuple_of_tuple.2);
    let too_long_tuple = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13);
    println!("{:?}", too_long_tuple.0);
    println!("{}", too_long_tuple.12);
    // 不能打印元素个数超过12个的元组
    // println!("{:?}",too_long_tuple);
    println!("{:?}", reverse((1i32, false)));
    println!("单个元组{:?}", (1, ));
    let (v1, v2) = (1i32, 2u8);
    println!("{:?},{}", v1, v2);
    let matrix = Matrix(1.0, 2.0, 3.3, 4.2);
    println!("{}", matrix);
}
